<!DOCTYPE html>
<html>
<head>
  <title>实时时间</title>
</head>
<body>
  <h1 id="current-time"></h1>

  <script>
    // 更新实时时间
    function updateCurrentTime() {
      var currentTime = new Date();
      var year = currentTime.getFullYear();
      var month = (currentTime.getMonth() + 1).toString().padStart(2, '0');
      var day = currentTime.getDate().toString().padStart(2, '0');
      var hours = currentTime.getHours().toString().padStart(2, '0');
      var minutes = currentTime.getMinutes().toString().padStart(2, '0');
      var seconds = currentTime.getSeconds().toString().padStart(2, '0');

      // 格式化时间
      var formattedTime = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;

      // 更新页面上的时间
      document.getElementById("current-time").textContent = formattedTime;
    }

    // 每秒更新一次时间
    setInterval(updateCurrentTime, 1000);

    // 页面加载完成后立即更新一次时间
    updateCurrentTime();
  </script>
</body>
</html>